 package handling.cashshop.handler;



import client.MapleCharacter;
import client.MapleClient;
import client.inventory.Item;
import handling.Auction.AuctionServer;
import handling.cashshop.CashShopServer;
import handling.channel.ChannelServer;
import handling.world.CharacterTransfer;
import handling.world.World;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import server.MTSItemsInfo;
import tools.MaplePacketCreator;
import tools.Pair;
import tools.data.input.LittleEndianAccessor;
import tools.packet.MTSCSPacket;
import tools.packet.MTSPacket;

import java.util.List;



















 public class CashShopOperation
 {
/*  24 */   private static final Logger log = LogManager.getLogger(CashShopOperation.class.getName());

   public static void LeaveCS(LittleEndianAccessor slea, MapleClient c, MapleCharacter chr, boolean CS) {
/*  27 */     if (chr == null) {
       return;
     }
/*  30 */     int channel = c.getChannel();
/*  31 */     ChannelServer toch = ChannelServer.getInstance(channel);
/*  32 */     if (toch == null) {
/*  33 */       log.error("玩家: " + chr.getName() + " 从" + (CS ? "商城" : "拍卖") + "离开发生错误.找不到频道[" + channel + "]的信息.");
/*  34 */       c.getSession().close();

       return;
     }
/*  38 */     World.ChannelChange_Data(new CharacterTransfer(chr), chr.getId(), c.getChannel());
/*  39 */     if (CS) {
/*  40 */       CashShopServer.getPlayerStorage().deregisterPlayer(chr);
     } else {
/*  42 */       AuctionServer.getPlayerStorage().deregisterPlayer(chr);
     }

/*  45 */     c.updateLoginState(1, c.getSessionIPAddress());
/*  46 */     c.announce(MaplePacketCreator.getChannelChange(c, toch.getPort()));
/*  47 */     chr.fixOnlineTime();

/*  49 */     chr.saveToDB(true, true);
/*  50 */     c.setPlayer(null);
/*  51 */     c.setReceiving(false);
   }

   public static void EnterCS(CharacterTransfer transfer, MapleClient c, boolean CS) {
/*  55 */     if (transfer == null) {
/*  56 */       c.getSession().close();
       return;
     }
/*  59 */     MapleCharacter chr = MapleCharacter.ReconstructChr(transfer, c, false);

/*  61 */     c.setPlayer(chr);
/*  62 */     c.setAccID(chr.getAccountID());

/*  64 */     if (!c.CheckIPAddress()) {
/*  65 */       c.getSession().close();
/*  66 */       log.info("erro:" + (CS ? "商城" : "拍卖") + "检测连接 - 2 " + (!c.CheckIPAddress() ? 1 : 0));

       return;
     }
/*  70 */     int state = c.getLoginState();
/*  71 */     boolean allowLogin = false;
/*  72 */     if ((state == 1 || state == 3) && 
/*  73 */       !World.isCharacterListConnected(c.loadCharacterNames(c.getWorld()))) {
/*  74 */       allowLogin = true;
     }

/*  77 */     if (!allowLogin) {
/*  78 */       c.setPlayer(null);
/*  79 */       c.getSession().close();
/*  80 */       log.info("erro:" + (CS ? "商城" : "拍卖") + "检测连接 - 3 " + (!allowLogin ? 1 : 0));
       return;
     }
/*  83 */     c.updateLoginState(2, c.getSessionIPAddress());
/*  84 */     if (CS) {
/*  85 */       CashShopServer.getPlayerStorage().registerPlayer(chr);
/*  86 */       c.announce(MTSCSPacket.INSTANCE.warpchartoCS(c));
/*  87 */       c.announce(MTSCSPacket.INSTANCE.warpCS(true));
/*  88 */       List<Pair<Item, String>> gifts = chr.getCashInventory().loadGifts();
/*  89 */       c.announce(MTSCSPacket.INSTANCE.商城道具栏信息(c));
/*  90 */       c.announce(MTSCSPacket.INSTANCE.商城礼物信息(gifts));
/*  91 */       c.announce(MTSCSPacket.INSTANCE.商城购物车(c.getPlayer(), false));
/*  92 */       c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(c.getPlayer()));
/*  93 */       c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(c.getPlayer()));
/*  94 */       c.getPlayer().getCashInventory().checkExpire(c);
     } else {
/*  96 */       AuctionServer.getPlayerStorage().registerPlayer(chr);
/*  97 */       c.announce(MTSPacket.startMTS(c));
/*  98 */       MTSItemsInfo mts = MTSItemsInfo.getInstance();

/* 100 */       MTSOperation.loadSellInfo(c, mts);

/* 102 */       MTSOperation.loadDoneInfo(c, mts);
     }
   }





   public static void CSUpdate(MapleClient c) {
/* 111 */     c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(c.getPlayer()));
   }

   public static void doCSPackets(MapleClient c) {
/* 115 */     c.announce(MTSCSPacket.INSTANCE.商城道具栏信息(c));
/* 116 */     c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(c.getPlayer()));
/* 117 */     c.getPlayer().getCashInventory().checkExpire(c);
   }
 }


/* Location:              C:\PGX\Server.jar!\handling\cashshop\handler\CashShopOperation.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */